package com.kakavr.base.exception;

import com.kakavr.result.constant.MsgConstants;


public class ValidateParamException extends RuntimeException {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 错误码
	 */
	private int code;
	/**
	 * 消息
	 */
	private String message;

	public ValidateParamException() {
		this.code = MsgConstants.MSG_CODE_ERROR;
		this.message = MsgConstants.MSG_CONTENT_ERROR;
	}

	public ValidateParamException(int code, String message) {
		this.code = code;
		this.message = message;
	}

	public ValidateParamException(int code, String content, String... payloads) {
		this.code = code;
		this.message = this.getContent(content, payloads);
	}

	/**
	 * 获取异常数字码
	 * 
	 * @return
	 */
	public int getCode() {
		return code;
	}

	/**
	 * 获取异常消息信息
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * 获取异常模版信息
	 * 
	 * @return
	 */
	private String getContent(String content, String... payloads) {
		if (content != null && payloads != null) {
			for (int i = 0; i < payloads.length; i++) {
				content = content.replace("{" + i + "}", payloads[i]);
			}
		}
		return content;
	}

}
